package com.avic.rong.userOrder.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.avic.rong.R;
import com.avic.rong.userOrder.bean.GetOrderTracesByJsonAllBean;
import com.avic.rong.userOrder.fragment.MineOrderFragment;
import com.avic.rong.utils.TimeUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by XinEr on 2019/7/19.
 * Describe:
 */
public class OrderPathListAdapter extends RecyclerView.Adapter<OrderPathListAdapter.ViewHolder> {
    private Context context;

    private   List<GetOrderTracesByJsonAllBean.OrderTracesListBean.TracesListBean.TracesBean> traces;

    public OrderPathListAdapter(Context context,  List<GetOrderTracesByJsonAllBean.OrderTracesListBean.TracesListBean.TracesBean> traces) {
        this.context = context;
        this.traces=traces;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.order_path_list_item, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        GetOrderTracesByJsonAllBean.OrderTracesListBean.TracesListBean.TracesBean tracesBean = traces.get(i);
        viewHolder.tv_traces_name.setText(tracesBean.getAcceptStation());


        try {
            String timeStamp = TimeUtil.dateToStamp(tracesBean.getAcceptTime() + "");
            String date = stampToDate(Long.parseLong(timeStamp));
            viewHolder.tv_traces_date.setText(date);
            String timeStampTime = TimeUtil.dateToStamp(tracesBean.getAcceptTime() + "");
            String time = stampToTime(Long.parseLong(timeStampTime));
            viewHolder.tv_traces_time.setText(time);

        } catch (ParseException e) {
            e.printStackTrace();

        }



        if (i == 0) {
           /* viewHolder.tv_shouhuo.setVisibility(View.VISIBLE);
            viewHolder.iv_samll_circle.setVisibility(View.GONE);*/
            viewHolder.iv_samll_circle.setImageResource(R.mipmap.ic_arrive_icon);
            viewHolder.tv_traces_name.setTextColor(context.getResources().getColor(R.color.color_98c727));
            viewHolder.tv_traces_time.setTextColor(context.getResources().getColor(R.color.color_98c727));
            viewHolder.tv_traces_date.setTextColor(context.getResources().getColor(R.color.color_98c727));
        }
       /* if (i == 5) {
            viewHolder.iv_samll_circle.setImageResource(R.mipmap.ic_arrive_icon);
        }*/
        if (i == (traces.size()-1)) {
            viewHolder.view_line.setVisibility(View.GONE);
            viewHolder.tv_shouhuo.setVisibility(View.GONE);
            viewHolder.iv_samll_circle.setVisibility(View.VISIBLE);

        }
        viewHolder.setIsRecyclable(false);
    }

    @Override
    public int getItemCount() {
        return traces.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView iv_samll_circle;
        private TextView tv_shouhuo;
        private TextView tv_traces_name;
        private TextView tv_traces_time;
        private TextView tv_traces_date;
        private LinearLayout ll_path;
        private View view_line;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            iv_samll_circle = itemView.findViewById(R.id.iv_samll_circle);
            tv_shouhuo = itemView.findViewById(R.id.tv_shouhuo);
            ll_path = itemView.findViewById(R.id.ll_path);
            view_line = itemView.findViewById(R.id.view_line);
            tv_traces_name = itemView.findViewById(R.id.tv_traces_name);
            tv_traces_time = itemView.findViewById(R.id.tv_traces_time);
            tv_traces_date = itemView.findViewById(R.id.tv_traces_date);
        }
    }

    /*
     * 将时间戳转换为时间
     */
    public  String stampToDate(long timeMillis){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd");
        Date date = new Date(timeMillis);
        return simpleDateFormat.format(date);
    }
    /*
     * 将时间戳转换为时间
     */
    public  String stampToTime(long timeMillis){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
        Date date = new Date(timeMillis);
        return simpleDateFormat.format(date);
    }


}
